package lesson01;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Auther: xiaofei
 * @Date: 2021/6/28 - 06 - 28 - 11:42
 * @Description: lesson01
 * @version: 1.0
 */
public class TestInetAddress {
    //这是一个main方法，是程序的入口：
    public static void main(String[] args) throws UnknownHostException {
        //查询本机地址
        InetAddress inetAddress1 = InetAddress.getByName("127.0.0.1");
        System.out.println(inetAddress1);
        InetAddress inetAddress3 = InetAddress.getByName("localhost");
        System.out.println(inetAddress3);
        InetAddress inetAddress4 = InetAddress.getLocalHost();
        System.out.println(inetAddress4);

        //查询网站ip地址
        InetAddress inetAddress2 = InetAddress.getByName("www.baidu.com");
        System.out.println(inetAddress2);
        System.out.println(inetAddress2.getHostAddress());
        System.out.println(inetAddress2.getHostName());
    }
}
